using System.Collections;
using UnityEngine;

public class TS_BunkerIntro : MonoBehaviour
{
	[Header("-- References --")]
	[SerializeField]
	private CameraManager playerCamera;

	[SerializeField]
	private Transform playerTransform;

	[SerializeField]
	private InventoryItem shelterKeys;

	[Space(5f)]
	[SerializeField]
	private bool isNightTime = true;

	[Header("- Camera Controls -")]
	[SerializeField]
	private float CameraFollowBB_Top;

	[SerializeField]
	private float CameraFollowBB_Bottom;

	[Header("- Shelter -")]
	[SerializeField]
	private Animator BunkerAnimator;

	[SerializeField]
	private INT_Chat Interaction;

	[SerializeField]
	private ParticleSystem VineParticle;

	[SerializeField]
	private AudioSource cutsceneSource;

	[SerializeField]
	private AudioClip[] CutsceneClips;

	[Space(5f)]
	[SerializeField]
	private CHATBOXTEXT EarlyTimeText;

	private void Start()
	{
		playerTransform = ((Component)PlayerManager.Instance).transform;
		if (!isNightTime)
		{
			((MonoBehaviour)this).StartCoroutine(DaytimeText());
		}
	}

	private void Update()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		if (((Component)PlayerManager.Instance._PMove._anim).GetComponent<SpriteRenderer>().color != new Color(0.1648718f, 0.2496044f, 0.6132076f) && isNightTime)
		{
			((Component)PlayerManager.Instance._PMove._anim).GetComponent<SpriteRenderer>().color = new Color(0.1648718f, 0.2496044f, 0.6132076f);
		}
		if (playerTransform.position.y < CameraFollowBB_Top && playerTransform.position.y > CameraFollowBB_Bottom)
		{
			playerCamera.FollowPlayerY = true;
			return;
		}
		if (((Component)playerCamera).transform.position.y != CameraFollowBB_Top && ((Component)playerCamera).transform.position.y != CameraFollowBB_Bottom)
		{
			if (Vector2.Distance(Vector2.op_Implicit(((Component)playerCamera).transform.position), Vector2.up * CameraFollowBB_Top) < Vector2.Distance(Vector2.op_Implicit(((Component)playerCamera).transform.position), Vector2.up * CameraFollowBB_Bottom))
			{
				((Component)playerCamera).transform.position = new Vector3(((Component)playerCamera).transform.position.x, CameraFollowBB_Top, ((Component)playerCamera).transform.position.z);
			}
			else
			{
				((Component)playerCamera).transform.position = new Vector3(((Component)playerCamera).transform.position.x, CameraFollowBB_Bottom, ((Component)playerCamera).transform.position.z);
			}
		}
		playerCamera.FollowPlayerY = false;
	}

	public void OpenBunker()
	{
		((Component)Interaction).gameObject.SetActive(false);
		((MonoBehaviour)this).StartCoroutine(BunkerOpenAnimation());
	}

	private IEnumerator BunkerOpenAnimation()
	{
		yield return null;
		ChatboxManager.Instance.EndText();
		PlayerManager.Instance._PMove.RotatePlayerAnim(Vector2.up);
		PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Cutscene;
		yield return (object)new WaitForSeconds(0.5f);
		cutsceneSource.PlayOneShot(CutsceneClips[1]);
		for (int i = 0; i < LightworldInventory.Instance.PlayerInventory.Count; i++)
		{
			if ((Object)(object)LightworldInventory.Instance.PlayerInventory[i] == (Object)(object)shelterKeys)
			{
				LightworldInventory.Instance.PlayerInventory.RemoveAt(i);
				LightworldInventory.Instance.PlayerInventory.Add(null);
				break;
			}
		}
		yield return (object)new WaitForSeconds(1f);
		BunkerAnimator.Play("BunkerOpen");
		cutsceneSource.PlayOneShot(CutsceneClips[0]);
		yield return (object)new WaitForSeconds(1f);
		VineParticle.Play();
		yield return (object)new WaitForSeconds(1.5f);
		PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Game;
	}

	private IEnumerator DaytimeText()
	{
		yield return (object)new WaitForSeconds(0.5f);
		DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Crying);
		PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Game;
		CutsceneUtils.RunFreshChat(EarlyTimeText, 0, ForcePosition: true, OnBottom: false);
	}

	private void OnDrawGizmos()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		Gizmos.color = Color.green;
		Gizmos.DrawLine(Vector2.op_Implicit(Vector2.up * CameraFollowBB_Bottom), Vector2.op_Implicit(Vector2.up * CameraFollowBB_Bottom));
	}
}
